package com.itheima.d3_traversal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class Test {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList<>();
        list.add("A");
        list.add("C");
        System.out.println(list);

        // iterator取完一个数据，就会往后移动一次 注意itetator.next()一个个
        Iterator<String> iterator = list.iterator(); // 默认占第一个，一个next 往后移动一个
        while(iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        System.out.println("===========");
        for (String str: list) {
            if (str.equals("A")){
                str ="B";
            }
            System.out.println(str);
        }
        System.out.println(list);

        System.out.println("==========");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {

            }
        });
        list.forEach((s) -> {
                System.out.println(s);
            }
        );
    }
}
